// 对于一个根节点来说，该树的深度等于其左子树与右子树中最大值 + 1
// 如果某二叉树中任意节点的左右子树的深度相差不超过 1，那么它就是一颗平衡二叉树
var isBalanced = function (root) {
  return recur(root) !== -1;
}

var recur = function (root)  {
  if (root == null) return 0;
  let left = recur(root.left);
  if (left === -1) return -1;
  let right = recur(root.right);
  if (right === -1) return -1;
  return Math.abs(left - right) > 1 ? -1 : Math.max(left, right) + 1;
}